package com.cskaoyan.controller;


import com.cskaoyan.bean.ConfigExpress;
import com.cskaoyan.bean.ConfigOrder;
import com.cskaoyan.bean.ConfigWX;
import com.cskaoyan.service.ConfigService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.bean.ConfigMall;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * @author： aurora
 * @data： 2021-05-10 17:52
 */

/*
    1.正则表达式
    2.修改数据后，数据库中的updateTime随之变动
 */

@RestController
@RequestMapping("admin/config")
@RequiresRoles("超级管理员")
public class ConfigController {

    @Autowired
    private ConfigService configService;

    //获取商城配置
    @GetMapping("mall")
    public BaseRespVo GetMallConfig(){
        ConfigMall configMall = configService.getMallConfig();
        return BaseRespVo.ok(configMall);
    }

    //修改商城配置
    @PostMapping("mall")
    public BaseRespVo UpdateMallConfig(@RequestBody@Valid ConfigMall configMall){
        configService.updateMallConfig(configMall);
        return BaseRespVo.ok();
    }

    //获取运费配置
    @GetMapping("express")
        public BaseRespVo GetExpressConfig(){
        ConfigExpress configExpress = configService.getExpressConfig();
        return BaseRespVo.ok(configExpress);
    }

    //修改运费配置
    @PostMapping("express")
    public BaseRespVo UpdateExpressConfig(@RequestBody@Valid ConfigExpress configExpress){
        configService.updateExpressConfig(configExpress);
        return BaseRespVo.ok();
    }

    //获取订单配置
    @GetMapping("order")
    public BaseRespVo GetOrderConfig(){
        ConfigOrder configOrder = configService.getOrderConfig();
        return BaseRespVo.ok(configOrder);
    }

    //修改订单配置
    @PostMapping("order")
    public BaseRespVo UpdateOrderConfig(@RequestBody@Valid ConfigOrder configOrder){
        configService.updateOrderConfig(configOrder);
        return BaseRespVo.ok();
    }

    //获取小程序配置
    @GetMapping("wx")
    public BaseRespVo GetWXConfig(){
        ConfigWX configWX = configService.getWXConfig();
        return BaseRespVo.ok(configWX);
    }

    //修改小程序配置
    @PostMapping("wx")
    public BaseRespVo UpdateWXConfig(@RequestBody@Valid ConfigWX configWX){
        configService.updateWXConfig(configWX);
        return BaseRespVo.ok();
    }

}
